package antlrtest;

import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;

public class PlayScript {

    public static void main(String[] args) {
        String script = "2+6+3";


        PlayScriptLexer lexer = new PlayScriptLexer(CharStreams.fromString(script));
        CommonTokenStream tokens = new CommonTokenStream(lexer);

        PlayScriptParser parser = new PlayScriptParser(tokens);
        ParseTree tree = parser.additiveExpression();
        System.out.println("this lisp style ast of: " + script);
        System.out.println(tree.toStringTree(parser));

        ASTEvaluator visitor = new ASTEvaluator();
        Integer result = visitor.visit(tree);
        System.out.println("\nValue of : " + script);
        System.out.println(result);
    }
}
